package com.zrx.controller;

import com.zrx.domain.ResponseResult;
import com.zrx.domain.dto.AddArticleDto;
import com.zrx.domain.dto.ArticleListDto;
import com.zrx.domain.entity.Article;
import com.zrx.domain.vo.PageVo;
import com.zrx.service.ArticleService;
import com.zrx.utils.BeanCopyUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 张荣欣
 * @create ：2022/10/8  16:02
 */
@RestController
@RequestMapping("/content/article")
@Api(tags = "文章")
public class Articlecontroller {

    @Autowired
    private ArticleService articleService;

    @PostMapping()
    @ApiOperation(value = "添加文章", notes = "添加文章")
    public ResponseResult add(@RequestBody AddArticleDto addArticleDto) {
        return articleService.add(addArticleDto);
    }

    @GetMapping("/list")
    @ApiOperation(value = "分页文章", notes = "分页文章")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, ArticleListDto articleListDto) {
        return articleService.pageArticleList(pageNum, pageSize, articleListDto);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取文章", notes = "根据id获取文章")
    public ResponseResult getByIdOneArticle(@PathVariable("id") Long id) {
        return articleService.getByIdOneArticle(id);
    }

    @PutMapping()
    @ApiOperation(value = "修改文章", notes = "修改文章")
    public ResponseResult updateArticle(@RequestBody AddArticleDto addArticleDto) {
        return articleService.updateArticle(addArticleDto);
    }
/**
 * @Description: [ids]

 * @return: com.zrx.domain.ResponseResult
 * @Author: 张荣欣
 * @Date: 9:46 2022/10/14
 */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "根据id删除文章", notes = "根据id删除文章")
    public ResponseResult deleteByIdArticle(@PathVariable("id") List<Long> ids) {
        articleService.removeByIds(ids);
        return ResponseResult.okResult();
    }
    /**
     *查询热门文章
     * @return
     */
    @GetMapping("/hotArticleList")
    @ApiOperation(value = "查询热门文章", notes = "查询热门文章 ")
    public ResponseResult hotArticleList(){
        return articleService.hotHouArticleList();
    }

}
